package com.zy.je.common.core.web.controller;

import com.alibaba.fastjson2.JSON;
import com.zy.je.common.core.utils.lang.StackUtil;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.text.StrUtil;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

/**
 * @author zy
 */
@Slf4j
public abstract class BaseController {
    @InitBinder
    public void customizeBinding(WebDataBinder binder) {
        //解决下划级开头的参数接收不到的问题
        //required to handle underscore prefixed fields ("_field")
        binder.setFieldMarkerPrefix(null);
    }

    protected static void logDebug(String str, Object... param) {
        String callerMethodName = StrUtil.format("({})", StackUtil.getCallerMethodName(2));
        log.debug(callerMethodName + str, param);
    }
    protected static void logInfo(String str, Object... param) {
        String callerMethodName = StrUtil.format("({})", StackUtil.getCallerMethodName(2));
        log.info(callerMethodName + str, param);
    }
    protected static void logError(String str, Object... param) {
        String callerMethodName = StrUtil.format("({})", StackUtil.getCallerMethodName(2));
        log.error(callerMethodName + str, param);
    }

    protected static String toJsonStr(Object src) {
        try {
            return JSON.toJSONString(src);
        } catch (Exception var2) {
            log.error("转json处理出错:{}", src);
            return null;
        }
    }
}
